//
//  LoginInputViewCell.m
//  OfficeBook
//
//  Created by 朱 琳 on 15/10/11.
//  Copyright (c) 2015年 sunny. All rights reserved.
//

#import "LoginUserNameViewCell.h"

NSInteger LoginUserNameCellTextFieldTag = 1000;

@interface LoginUserNameViewCell()<UITextFieldDelegate>
    
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UITextField *contentTextField;

@end

@implementation LoginUserNameViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.iconImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"userIcon"]];
    self.contentTextField = [[UITextField alloc]init];
    self.contentTextField.placeholder = @"Enter User Name";
    self.contentTextField.font = [UIFont systemFontOfSize:15];
    self.contentTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.contentTextField.keyboardType = UIKeyboardTypeDefault;
    self.contentTextField.tag = LoginUserNameCellTextFieldTag;
    self.contentTextField.delegate = self;
    
    [self.contentView addSubview:self.iconImageView];
    [self.contentView addSubview:self.contentTextField];
    
    [self.iconImageView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.leftMargin);
        make.centerY.equalTo(self.contentView.centerY);
        make.width.equalTo(@25);
        make.height.equalTo(@25);
    }];
    
    [self.contentTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView.right).offset(15);
        make.right.equalTo(self.contentView.rightMargin);
        make.centerY.equalTo(self.contentView.centerY);
        make.height.equalTo(@44);
    }];
    
    return self;
}

@synthesize userName = _userName;
-(void)setUserName:(NSString *)userName {
    _userName = userName;
    self.contentTextField.text = userName;
}

-(NSString *)userName {
    _userName = self.contentTextField.text;
    return _userName;
}

#pragma mark UITextField delegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.contentTextField resignFirstResponder];
    return YES;
}
@end
